﻿using System;
using System.Collections.Generic;
using System.Text;

namespace BBMS.DLL.DataContract
{
    public class HoaDonXuat : ChungTuBase
    {
        public HoaDonXuat()
        {
            this.LoaiCT = "HDX";
            this.IsChi = false;
        }

        public HoaDonXuat(long id, string maCT, string soCT,
             DateTime ngayCT, DateTime ngayHT, DateTime ngayTTDuKien,
             DateTime ngayTT, TrangThaiThanhToan trangThaiTT,
             string maSoHS, string maNCC, string maQuay,
             long giaTriChuaThue, int thueSuat, long giaTriThue,
             long giaTriCT, long giaTriDaTT, string ghiChu,
             int nvID)
            : base(id, "HDX", maCT, soCT, ngayCT, ngayHT, ngayTTDuKien, ngayTT, trangThaiTT, maSoHS,
                maNCC, maQuay, "", giaTriChuaThue, 0, giaTriChuaThue, thueSuat, giaTriThue, giaTriCT,
                giaTriDaTT, "", false, false, ghiChu, nvID)
        {
            this.LoaiCT = "HDX";
            this.IsChi = false;

        }

        public override System.Data.DataTable GetObjectDataTable()
        {
            System.Data.DataTable dt = new System.Data.DataTable(this.TableName);

            dt.Columns.Add("ID", typeof(String));
            dt.Columns.Add("MaCT", typeof(String));
            dt.Columns.Add("SoCT", typeof(String));
            dt.Columns.Add("LoaiCT", typeof(String));
            dt.Columns.Add("NgayCT", typeof(DateTime));
            dt.Columns.Add("NgayHT", typeof(DateTime));
            dt.Columns.Add("NgayTTDuKien", typeof(DateTime));
            dt.Columns.Add("NgayTT", typeof(DateTime));
            dt.Columns.Add("TrangThaiTT", typeof(int));
            dt.Columns.Add("MaHoSo", typeof(String));
            dt.Columns.Add("MaNCC", typeof(String));
            dt.Columns.Add("MaQuay", typeof(String));

            dt.Columns.Add("GiaTriHangHoa", typeof(long));
            dt.Columns.Add("ChietKhau", typeof(long));
            dt.Columns.Add("GiaTriChuaThue", typeof(long));
            dt.Columns.Add("ThueSuat", typeof(int));
            dt.Columns.Add("GiaTriThue", typeof(long));
            dt.Columns.Add("GiaTriCT", typeof(long));
            dt.Columns.Add("GiaTriDaTT", typeof(long));

            dt.Columns.Add("GhiChu", typeof(String));
            dt.Columns.Add("IsChi", typeof(bool));

            dt.Columns.Add("NVID", typeof(int));

            return dt;
        }
        public override System.Data.DataRow ObjectToDataRow()
        {
            System.Data.DataRow row = this.GetObjectDataTable().NewRow();
            row["ID"] = this.ID;
            row["MaCT"] = this.MaCT;
            row["SoCT"] = this.SoCT;
            row["LoaiCT"] = this.LoaiCT;
            row["NgayCT"] = this.NgayCT;
            row["NgayHT"] = this.NgayHT;
            row["NgayTTDuKien"] = this.NgayTTDuKien;
            row["NgayTT"] = this.NgayTT;
            row["TrangThaiTT"] = (int)this.TrangThaiTT;
            row["MaHoSo"] = this.MaHoSo;
            row["MaNCC"] = this.MaNCC;
            row["MaQuay"] = this.MaQuay;

            row["GiaTriHangHoa"] = this.GiaTriHangHoa;
            row["ChietKhau"] = this.ChietKhau;
            row["GiaTriChuaThue"] = this.GiaTriChuaThue;
            row["ThueSuat"] = this.ThueSuat;
            row["GiaTriThue"] = this.GiaTriThue;
            row["GiaTriCT"] = this.GiaTriCT;
            row["GiaTriDaTT"] = this.GiaTriDaTT;

            row["GhiChu"] = this.GhiChu;
            row["IsChi"] = this.IsChi;

            row["NVID"] = this.NVID;

            return row;
        }

        public override void UpdateInsertedID(MySql.Data.MySqlClient.MySqlCommand cmd)
        {
            cmd.CommandText = "SELECT LAST_INSERT_ID()";
            this.ID = CommonTools.Helper.StringToLong(cmd.ExecuteScalar().ToString());
        }
        public override bool CanDelete(MySql.Data.MySqlClient.MySqlCommand cmd, System.Data.DataRow row)
        {
            return false;
        }
        public override BBMS.DLL.Base.ObjectBase DataRowToObject(System.Data.DataRow row)
        {
            HoaDonXuat obj = null;
            try
            {
                obj = new HoaDonXuat(
                    CommonTools.Helper.StringToLong(row["ID"].ToString()),
                    row["MaCT"].ToString(),
                    row["SoCT"].ToString(),
                    (DateTime)row["NgayCT"],
                    (DateTime)row["NgayHT"],
                    (DateTime)row["NgayTTDuKien"],
                    (DateTime)row["NgayTT"],
                    (TrangThaiThanhToan)(CommonTools.Helper.StringToInt(row["TrangThaiTT"].ToString())),
                    row["MaHoSo"].ToString(),
                    row["MaNCC"].ToString(),
                    row["MaQuay"].ToString(),
                    CommonTools.Helper.StringToLong(row["GiaTriChuaThue"].ToString()),
                    CommonTools.Helper.StringToInt(row["ThueSuat"].ToString()),
                    CommonTools.Helper.StringToLong(row["GiaTriThue"].ToString()),
                    CommonTools.Helper.StringToLong(row["GiaTriCT"].ToString()),
                    CommonTools.Helper.StringToLong(row["GiaTriDaTT"].ToString()),
                    row["GhiChu"].ToString(),
                    CommonTools.Helper.StringToInt(row["NVID"].ToString()));
            }
            catch { }
            return obj;
        }

        public override BBMS.DLL.Base.ObjectBase DataReaderToObject(MySql.Data.MySqlClient.MySqlDataReader row)
        {
            HoaDonXuat obj = null;
            try
            {
                obj = new HoaDonXuat(
                    CommonTools.Helper.StringToLong(row["ID"].ToString()),
                    row["MaCT"].ToString(),
                    row["SoCT"].ToString(),
                    (DateTime)row["NgayCT"],
                    (DateTime)row["NgayHT"],
                    (DateTime)row["NgayTTDuKien"],
                    (DateTime)row["NgayTT"],
                    (TrangThaiThanhToan)(CommonTools.Helper.StringToInt(row["TrangThaiTT"].ToString())),
                    row["MaHoSo"].ToString(),
                    row["MaNCC"].ToString(),
                    row["MaQuay"].ToString(),
                    CommonTools.Helper.StringToLong(row["GiaTriChuaThue"].ToString()),
                    CommonTools.Helper.StringToInt(row["ThueSuat"].ToString()),
                    CommonTools.Helper.StringToLong(row["GiaTriThue"].ToString()),
                    CommonTools.Helper.StringToLong(row["GiaTriCT"].ToString()),
                    CommonTools.Helper.StringToLong(row["GiaTriDaTT"].ToString()),
                    row["GhiChu"].ToString(),
                    CommonTools.Helper.StringToInt(row["NVID"].ToString()));
            }
            catch { }
            return obj;
        }
    }

    /*
    public class HoaDonXuat : BBMS.DLL.Base.ObjectBase
    {
        public long ID;
        public string MaCT;
        public string SoCT;
        public string LoaiCT = "HDX";
        public DateTime NgayCT;
        public DateTime NgayHT; // ngay hoach toan
        public DateTime NgayTT;
        public DateTime NgayTTDuKien;
        public string MaNCC;
        public string MaQuay;
        public string MaHoSo;
        public long GiaTri;
        public int ThueSuat;
        public long GiaTriThue;
        public string GhiChu;
        public bool IsChi = false;
        public TrangThaiThanhToan TrangThaiTT = TrangThaiThanhToan.ChuaTT;
        public int NVID = 0;

        public HoaDonXuat()
        {
        }

        public HoaDonXuat(long id, string maCT, string soCT,
            DateTime ngayCT, DateTime ngayHT, DateTime ngayTTDuKien, DateTime ngayTT, string maHoSo,
            string maNCC, string maQuay,
            long giatri, int thuesuat, long giatrithue, string ghiChu, TrangThaiThanhToan trangThaiTT, int nvid)
        {
            this.ID = id;
            this.MaCT = maCT;
            this.SoCT = soCT;
            this.NgayCT = ngayCT;
            this.NgayHT = ngayHT;
            this.NgayTT = ngayTT;
            this.NgayTTDuKien = ngayTTDuKien;
            this.MaHoSo = maHoSo;
            this.MaNCC = maNCC;
            this.MaQuay = maQuay;
            this.GiaTri = giatri;
            this.ThueSuat = thuesuat;
            this.GiaTriThue = giatrithue;
            this.GhiChu = ghiChu;
            this.TrangThaiTT = trangThaiTT;
            this.NVID = nvid;
        }

        public override object Key
        {
            get
            {
                return this.ID;
            }
        }
        public override string Name
        {
            get
            {
                return this.MaCT + "-" + this.SoCT;
            }
        }
        public override string TableName
        {
            get
            {
                return "bill";
            }
        }

        public override string[] KeyFields
        {
            get
            {
                return new string[] { "MaCT", "SoCT" };
            }
        }

        public override string[] IDFields
        {
            get
            {
                return new string[] { "ID" };
            }
        }

        public override System.Data.DataTable GetObjectDataTable()
        {
            System.Data.DataTable dt = new System.Data.DataTable(this.TableName);
            dt.Columns.Add("ID", typeof(String));
            dt.Columns.Add("MaCT", typeof(String));
            dt.Columns.Add("SoCT", typeof(String));
            dt.Columns.Add("LoaiCT", typeof(String));
            dt.Columns.Add("NgayCT", typeof(DateTime));
            dt.Columns.Add("NgayHT", typeof(DateTime));
            dt.Columns.Add("NgayTTDuKien", typeof(DateTime));
            dt.Columns.Add("NgayTT", typeof(DateTime));
            dt.Columns.Add("MaHoSo", typeof(String));
            dt.Columns.Add("MaNCC", typeof(String));
            dt.Columns.Add("MaQuay", typeof(String));
            dt.Columns.Add("GiaTri", typeof(long));
            dt.Columns.Add("ThueSuat", typeof(int));
            dt.Columns.Add("GiaTriThue", typeof(long));
            dt.Columns.Add("GhiChu", typeof(String));
            dt.Columns.Add("TrangThaiTT", typeof(int));
            dt.Columns.Add("IsChi", typeof(bool));
            dt.Columns.Add("NVID", typeof(int));

            return dt;
        }
        public override System.Data.DataRow ObjectToDataRow()
        {
            System.Data.DataRow row = this.GetObjectDataTable().NewRow();
            row["ID"] = this.ID;
            row["MaCT"] = this.MaCT;
            row["SoCT"] = this.SoCT;
            row["LoaiCT"] = this.LoaiCT;
            row["IsChi"] = this.IsChi;
            row["NgayCT"] = this.NgayCT;
            row["NgayHT"] = this.NgayHT;
            row["NgayTTDuKien"] = this.NgayTTDuKien;
            row["NgayTT"] = this.NgayTT;
            row["MaHoSo"] = this.MaHoSo;
            row["MaNCC"] = this.MaNCC;
            row["MaQuay"] = this.MaQuay;
            row["GiaTri"] = this.GiaTri;
            row["ThueSuat"] = this.ThueSuat;
            row["GiaTriThue"] = this.GiaTriThue;
            row["GhiChu"] = this.GhiChu;
            row["TrangThaiTT"] = (int)this.TrangThaiTT;
            row["NVID"] = this.NVID;
            return row;
        }

        public override void UpdateInsertedID(MySql.Data.MySqlClient.MySqlCommand cmd)
        {
            cmd.CommandText = "SELECT LAST_INSERT_ID()";
            this.ID = CommonTools.Helper.StringToLong(cmd.ExecuteScalar().ToString());
        }
        public override bool CanDelete(MySql.Data.MySqlClient.MySqlCommand cmd, System.Data.DataRow row)
        {
            return true;
        }
        public override BBMS.DLL.Base.ObjectBase DataRowToObject(System.Data.DataRow row)
        {
            HoaDonXuat obj = null;
            try
            {
                obj = new HoaDonXuat(CommonTools.Helper.StringToLong(row["ID"].ToString()),
                    row["MaCT"].ToString(),
                    row["SoCT"].ToString(),
                    (DateTime)row["NgayCT"],
                    (DateTime)row["NgayHT"],
                    (DateTime)row["NgayTT"],
                    (DateTime)row["NgayTTDuKien"],
                    row["MaHoSo"].ToString(),
                    row["MaNCC"].ToString(),
                    row["MaQuay"].ToString(),
                    CommonTools.Helper.StringToLong(row["GiaTri"].ToString()),
                    CommonTools.Helper.StringToInt(row["ThueSuat"].ToString()),
                    CommonTools.Helper.StringToLong(row["GiaTriThue"].ToString()),
                    row["GhiChu"].ToString(),
                    (TrangThaiThanhToan)(CommonTools.Helper.StringToInt(row["TrangThaiTT"].ToString())),
                    CommonTools.Helper.StringToInt(row["NVID"].ToString()));
            }
            catch { }
            return obj;
        }
        public override string ExWhereClause
        {
            get
            {
                return " LoaiCT = 'HDX' ";
            }
        }
        public override BBMS.DLL.Base.ObjectBase DataReaderToObject(MySql.Data.MySqlClient.MySqlDataReader rd)
        {
            HoaDonXuat obj = null;
            try
            {
                obj = new HoaDonXuat(CommonTools.Helper.StringToLong(rd["ID"].ToString()),
                    rd["MaCT"].ToString(),
                    rd["SoCT"].ToString(),
                    (DateTime)rd["NgayCT"],
                    (DateTime)rd["NgayHT"],
                    (DateTime)rd["NgayTT"],
                    (DateTime)rd["NgayTTDuKien"],
                    rd["MaHoSo"].ToString(),
                    rd["MaNCC"].ToString(),
                    rd["MaQuay"].ToString(),
                    CommonTools.Helper.StringToLong(rd["GiaTri"].ToString()),
                    CommonTools.Helper.StringToInt(rd["ThueSuat"].ToString()),
                    CommonTools.Helper.StringToLong(rd["GiaTriThue"].ToString()),
                    rd["GhiChu"].ToString(),
                    (TrangThaiThanhToan)(CommonTools.Helper.StringToInt(rd["TrangThaiTT"].ToString())),
                    CommonTools.Helper.StringToInt(rd["NVID"].ToString()));
            }
            catch { }
            return obj;
        }
    }
     */
}
